<?php echo $this->Javascript->link('jquery.dataTables.min'); ?>
<?php echo $this->Javascript->link('question_module'); ?>
<?php echo $this->Javascript->link('answers_module'); ?>
<?php 
	echo $this->Html->script('stickytooltip');
	echo $this->Html->css('stickytooltip');
?>
<?php echo $this->Html->css('question_module'); ?>
<div class="box_mid">
	<?php echo $this->Session->flash(); ?>
	<div class="box_mid_content">
		<div class="box_mid_content_top">
			<span class="style1">All Questions</span>
			<div style="clear: both;"></div>
		</div>
		<div class="hr"></div>
		<div class="box_mid_content_mid">
			<table>
				<thead>
					<tr>
						<th><?echo ("SL");?></th>
						<th><?echo ("Content");?></th>
						<th><?php echo $this->Paginator->sort('QuestionType.name', 'Type', array('update' => 'MainContent','indicator' => 'loading', 'type' => 'GET'))?></th>
						<th><?php echo $this->Paginator->sort('QuestionLevel.name', 'Level', array('update' => 'MainContent','indicator' => 'loading', 'type' => 'GET'))?></th>
						<th><?php echo $this->Paginator->sort('User.first_name', 'Owner', array('update' => 'MainContent','indicator' => 'loading', 'type' => 'GET'))?></th>
						<th><?php echo $this->Paginator->sort('Question.active', 'Status', array('update' => 'MainContent','indicator' => 'loading', 'type' => 'GET'))?></th>
						<th><?php echo $this->Paginator->sort('Question.created', 'Created', array('update' => 'MainContent','indicator' => 'loading', 'type' => 'GET'))?></th>
						<th><?echo ("Actions");?></th>
					</tr>
				</thead>
				<tbody>
				<?php if( isset($questions) && !empty($questions)){
				$sl = 0;
				foreach ($questions as $row) {
					$sl ++;
					echo "<tr>";
					
					echo "<td>";
						echo $sl;
					echo "</td>";
						
					echo "<td>";
						echo $this->Html->Image(
								'view_details.png',
								 array('data-tooltip' => 'sticky-view-'.$row['Question']['id'],
									'height' => '30' , 'weight'=>'30', 'style' => 'cursor: pointer;')
							);
					echo "</td>";
					
					echo "<td>";
						echo $row['QuestionType']['name'];
					echo "</td>";
					
					echo "<td>";
						echo $row['QuestionLevel']['name'];
					echo "</td>";
					
					echo "<td>";
						echo h($row['User']['first_name']).' '.h($row['User']['last_name']);
					echo "</td>";
					echo "<td>";
						if ($row['Question']['active']==1) {
									echo "Active";
								} else {
									echo "Inactive";
								}
					echo "</td>";
					echo "<td>";
						echo date('d-M-Y',strtotime($row['Question']['created']));
					echo "</td>";
					echo "<td>";
						echo "<span class='icon'>";
							echo $this->Ajax->link(
									$this->Html->image(SITE_URL.'img/view.png', array('boder' => '0', 'alt' => 'View', 'title' => 'View')), 
										SITE_URL.'questions/ShowQuestion/'.$row['Question']['id'], 
										array('update' => 'MainContent','indicator' => 'loading', 'type' => 'GET', 'escape' => false)
							);
						echo "</span>";
						
						echo "<span class='icon'>";
							echo $this->Ajax->link(
									$this->Html->image(SITE_URL.'img/edit.png', array('boder' => '0', 'alt' => 'Edit Question', 'title' => 'Edit Question')), 
									SITE_URL.'questions/edit/'.$row['Question']['id'], 
									array('update' => 'MainContent','indicator' => 'loading', 'type' => 'GET', 'escape' => false)
									);
						echo "</span>";
						
						if ($row['Question']['active']==0) {
							echo "<span class='icon'>";
							echo $this->Ajax->link(
								$this->Html->image(SITE_URL.'/img/approve.png', array('boder' => '0', 'alt' => 'Make Active', 'title' => 'Make Active')),
									'/Question/makeActive/'.$row['Question']['id'], 
									array('update' => 'MainContent','indicator' => 'loading', 'type' => 'GET', 'escape' => false)
										);
							echo "</span>";
						}
									
						echo "<span class='icon'>";
							echo $this->Ajax->link(
									$this->Html->image(SITE_URL.'img/delete.png',array('boder' => '0', 'alt' => 'Delete', 'title' => 'Delete')),
									SITE_URL.'questions/delete/'.$row['Question']['id'],
									array('update' => 'MainContent','indicator' => 'loading', 'type' => 'POST', 'escape' => false),
											'Are you sure you want to delete this question?');
						echo "</span>";
						
					echo "</td>";
					
					echo "</tr>";
				}}
				else {
					echo "<tr><td colspan=10><br/><br/>No Data</td></tr>";
				}
				?>
				</tbody>
			</table>
			<?php
				echo "<div class='box_pagging'>";
					echo "<div class='box_pagging_info box_pagging_info_boder'>";
						echo $this->Paginator->counter('Total of record {:count}, starting on record {:start}, ending on {:end}');
					echo "</div>";
					echo "<div class='box_pagging_info'>";
						echo $this->Paginator->first("<< First", array('update' => 'MainContent','indicator' => 'loading', 'type' => 'GET'));
					echo "</div>";
					echo "<div class='box_pagging_info'>";
						echo $this->Paginator->prev(' << ' . __('previous'),array('update' => 'MainContent','indicator' => 'loading', 'type' => 'GET'), null, array('class' => 'prev disabled'));
					echo "</div>";
					echo "<div class='box_pagging_info'>";
						echo $this->Paginator->numbers(array('update' => 'MainContent','indicator' => 'loading', 'type' => 'GET'));
					echo "</div>";
					echo "<div class='box_pagging_info'>";
						echo $this->Paginator->next(__('next'). ' >>', array('update' => 'MainContent','indicator' => 'loading', 'type' => 'GET'), null, array('class' => 'next disabled'));
					echo "</div>";
					echo "<div class='box_pagging_info'>";
						echo $this->Paginator->last("Last >>", array('update' => 'MainContent','indicator' => 'loading', 'type' => 'GET'));
					echo "</div>";
					echo "<div class='box_pagging_info box_pagging_info_boder'>";
						echo $this->Paginator->counter('Number of record {:page} of {:pages}');
					echo "</div>";
				echo "</div>";
			?>
		</div>
	</div>
</div>
<?php
 	if( isset($questions) && !empty($questions)){
	 	echo "<div id='mystickytooltip' class='stickytooltip'>";
	 	foreach ($questions as $row) {
			
			echo "<div id='sticky-view-".$row['Question']['id']."' class='atip' style='width:500px'>";
			echo $row['Question']['content'];
			/*
			$i = 0;
			foreach ($row['Answer'] as $answer){
				$i = $i + 1;
				if ($answer['answer']) {
					echo "Anser $i ------ anwser true ------";
				}else {
					echo "Anser $i";
				}
				echo $answer['content'];
			}*/
			echo "</div>";
		} 
 	}
?>